from pymongo import MongoClient

class TaobaoStorage:
    def __init__(self):
        self.mongo_config = {
            "mongo_url": "127.0.0.1:27017",
            "db": "taobao",
            "collection": "product",
            "user": None,
            "pwd": None
        }
        try:
            #连接到mongo
            self.cilent = MongoClient(self.mongo_config['mongo_url'])

            #连接数据库
            self.db = self.cilent[self.mongo_config['db']]

            #连接到集合
            self.db_coll = self.db[self.mongo_config['collection']]

        except Exception:
            print('collect mongo failed')

    def insert_one(self, data):
        '''

        :param data: dict
        :return:
        '''
        self.db_coll.insert_one(data)
        print('写入数据成功')